package MaintMenu.VenPricingUpdTBLN;

import CreateNewItem.WIN.DnkFunctions;

import java.sql.*;
import java.text.DecimalFormat;

/**
 * Created with IntelliJ IDEA.
 * User: Jason
 * Date: 8/20/13
 * Time: 7:44 PM
 * To change this template use File | Settings | File Templates.
 */
public class TYGcuftPkgUpdate {
    int x=0;
    int cc=0;
    String table="";
    public  TYGcuftPkgUpdate(){
        DecimalFormat df = new DecimalFormat("#.##");

        try {
            DnkFunctions dnk = new DnkFunctions();
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            String dataSourceName = "dbLI";
            String dbURL = (new StringBuilder()).append("jdbc:odbc:").append(dataSourceName).toString();
            Connection con = DriverManager.getConnection(dbURL, "", "");
            Statement st = con.createStatement();
            Statement st1 = con.createStatement();
            Statement st2 = con.createStatement();
            Statement st3 = con.createStatement();
            Statement st4 = con.createStatement();
            Statement st5 = con.createStatement();
            Statement st6 = con.createStatement();
            int cat=0;
            while (cat<1)  {
                if (cat==0){
                    table="TBLBCN_TEMPOUT2";
                }
                if (cat==1){
                    table="TBLHFN_TEMPOUT2";
                }
                if (cat==2){
                    table="TBLOTN_TEMPOUT2";
                }
                if (cat==3){
                    table="TBLCLN_TEMPOUT2";
                }
                if (cat==4){
                    table="TBLMRN_TEMPOUT2";
                }
//                if (cat==5){
//                    table="TBLLTN";
//                }

                try
                {
                    st3.execute("select * from "+table+";");
                    ResultSet rs1 = st3.getResultSet();
                    if(rs1 != null)
                        while(rs1.next())
                        {
    //                        String CONTROL = rs1.getString("CONTROL").replaceAll("null", " ");
                            String dnkNum=rs1.getString("part#");
                            double pkg = rs1.getDouble("tyg_tw_k");
                            double cuft = rs1.getDouble("tyg_tw_c");

//                            System.out.println("old cuft"+cuft);
                            double newc = (cuft/pkg);
//                            System.out.println("new cuft"+df.format(newc));


                            try
                            {
                                String sql= "update  "+table+" set tyg_tw_c="+df.format(newc)+" where [part#]='"+dnkNum+"';";
//                                System.out.println(sql);
                                st2.execute(sql);
                            }
                            catch(SQLException er) { }
                        }

                }
                catch(SQLException er)
                {
                    er.printStackTrace();
                }
                cat++;
            }

            st.close();
            st1.close();
            st2.close();
            st3.close();
            st4.close();
            st5.close();
            st6.close();
            con.close();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            System.out.println(e);
        } catch (SQLException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            System.out.println(e);
        }
    }


}
